package leetcode.easy.q27;

public class Q {
}

class Solution {
    public int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0) return 0;
        int gap = 0, currentIndex = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                //currentIndex必须要被修改过才有效，说明存在有效结果的移动
                nums[currentIndex = i - gap] = nums[i];
            } else {
                gap++;
            }
        }
        return currentIndex + 1;//默认0个
    }
}